package Runde8;

public class Logistician extends TwoWayWorker{

	private static int counter = 0;
	private final int nr;
	
	/**
	 * @precondition None of the arguments may be empty (null).
	 * @postcondition Creates a logistician.
	 */
	public Logistician(Storage source, Storage target, int wTime, int toGet, int toGive, Company comp) {
		super(source,target, wTime, toGet, toGive, comp);
		this.nr = (counter++ % 2) + 1;
	}
	
	/**
	 * @postcondition Executed when Thread is started
	 * 					If all Logisticians are done and the company is still in Operation, the company's operation will be stopped
	 */
	public void run() {
		super.run();
		if (!super.target.hasActiveWorkers() && super.comp.inOperation()) {
			super.comp.report();
		}
	}
	
	/**
	 * @postcondition Returns a readable identification of the worker.
	 */
	public String toString() {
		return "Logistician " + nr;
	}

}
